<template>
  <h1>表格组件</h1>
  <el-table :data="tableData" style="width: 100%">
<!--    pro=property 设置当前列的内容为数组中对象的某个属性-->
    <el-table-column prop="date" label="Date" width="180" />
    <el-table-column prop="name" label="Name" width="180" />
    <el-table-column prop="address" label="Address" />
  </el-table>
  <h3>自己的员工列表</h3>
  <el-table :data="arr" stripe align="center">
    <el-table-column type="index" label="编号" width="180" />
    <el-table-column prop="name" label="名字" width="180" />
    <el-table-column prop="salary" label="工资" width="180" />
    <el-table-column prop="job" label="工作" width="180" />

<!--    自定义列开始-->
    <el-table-column label="操作">
      <template #default="scope">
<!--        编辑按钮-->
<!--        <el-button size="small" @click="handleEdit(scope.$index, scope.row)"-->
<!--        >Edit</el-button-->
<!--        >-->
<!--        scope=>变量中装着当前行对应的数据,scope.$index=>当前行对应的下标,scope.row=>当前行对应的数组中的对象-->
        <el-button
            size="small"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
        >Delete</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";

const handleDelete = (i,emp) =>{
  if (confirm("您确认删除"+emp.name+"吗?")){
    arr.value.splice(i,1);
  }
}
const arr = ref([{name:"张三",salary:3000,job:"销售"},
  {name:"李四",salary:4000,job:"人事"},
  {name:"张三",salary:5000,job:"程序员"}
]);
const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
</script>
